package com.duck.communication.service.impl;

import com.duck.common.utils.ContentProcessUtil;
import com.duck.communication.dao.PostDao;
import com.duck.communication.domain.dto.PostInfoDto;
import com.duck.communication.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {

    @Autowired
    private PostDao postDao;

    @Override
    public Integer publishPost(HashMap<String, Object> post) {
        return postDao.insertPostById(post);
    }

    @Override
    public List<HashMap<String, Object>> getAllPost() {
        List<HashMap<String, Object>> posts = postDao.getAllPost();
        ContentProcessUtil.processPosts(posts);
        return posts;
    }

    @Override
    public List<HashMap<String, Object>> getPostByUserId(String userId) {
        List<HashMap<String, Object>> posts = postDao.getPostByUserId(userId);
        ContentProcessUtil.processPosts(posts);
        return posts;
    }

    @Override
    public Integer updatePost(HashMap<String, Object> info) {
        return postDao.updatePostByUserIdAndPostId(info);
    }

    @Override
    public List<HashMap<String, Object>> selectCategory() {
        return postDao.selectCategory();
    }

    @Override
    public PostInfoDto searchPostInfo(String postId) {
        return postDao.searchPostInfo(postId);
    }
}